const express = require('express');
const router = express.Router();
const user = require('../../bin/control/userControl');
const teacher = require('../../bin/models/teacherModels');
module.exports =
    router.post('/userLogin', function (req, res, next) { // 用户登录
       user.userLogin(req.body.code,(_id)=>{
       res.send(_id)
       })
    });
    router.post('/addUser', function (req, res, next) { // 用户添加详细信息
      user.updateuser(req.body,(result)=>{
         res.send('success')
      })
    });
router.post('/addUserS', function (req, res, next) { // 用户添加详细信息
      console.log(req.body)
      user.adduser(req.body, (result) => {
        // console.log(result)
        res.send(result)
      })
    });
    router.post('/addTeacher', function (req, res, next) { // 用户添加老师
      teacher.insert(req.body,(result)=>{
         res.send('success')
      })
   });
    router.get('/alluser', function (req, res, next) { // 查询所有人
      user.findAlluser((allData)=>{
       for(let i in allData){
          allData[i].number = parseInt(i)+1
          switch(allData[i].gender){
             case 0:allData[i].gender='保密';break;
             case 1:allData[i].gender='男';break;
             case 2:allData[i].gender='女';break;
          }
       }
         res.send(allData)
      })
   //    console.log(req.body)
   });
   router.post('/deleteuser', function (req, res, next) { // 删除用户
      let _id = req.body._id
      user.deleteOneuser(_id,(allData)=>{
         res.send(allData)
      })
   //    console.log(req.body)
   });
   router.post('/isuseradmin',function(req,res,next){
      let _id = req.body._id
      user.isUserAdmin(_id,(userres)=>{
         res.send(userres)
      })
   })
   
   router.post('/userUpdate',function(req,res,next){
      let userData = req.body
      user.updateuserSet(userData,()=>{
         res.send('success')
      })
   })
   router.post('/teacherUpdate',function(req,res,next){
    let userData = req.body
    user.updateTeacherSet(userData,()=>{
       res.send('success')
    })
 })

